package org.util;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class CreateDataSource {
	private static Context context=null;
	private static DataSource ds=null;
	private static Connection con=null;
	public static Connection getDataSource(){
		if(context==null|ds==null){
			try {
				context=new InitialContext();
				ds=(DataSource)context.lookup("java:comp/env/SchoolDB");
				con=ds.getConnection();
			} catch (NamingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return con;
	}
}
